package de.upb.aquarium.water;

public class CircleWave implements Wave, Cloneable {
	
	private double centerX, centerY;
	private double waveLength;
	private double rotationTime;
	private double amplitude;
	private double radius;
	private double dampeningParameter;
	
	public CircleWave(
			double centerX,
			double centerY,
			double waveLength,
			double rotationTime,
			double amplitude,
			double dampeningParameter) {
		
		this.centerX = centerX;
		this.centerY = centerY;
		this.waveLength = waveLength;
		this.rotationTime = rotationTime;
		this.amplitude = amplitude;
		this.dampeningParameter = dampeningParameter;
	}
	
	@Override
	public double getHighAt(double x, double y) {
		
		double distFromCenter
			= Math.sqrt((x - centerX)*(x - centerX) + (y - centerY)*(y - centerY));
				
		if (distFromCenter > radius
		 || distFromCenter < (radius - waveLength))
		{
			return 0;
		}
		else
		{
			double d = (distFromCenter - radius) + waveLength;
			double dampeningFactor = 1.0/(1.0 + distFromCenter*(1.0/dampeningParameter));
			
			return -Math.sin(2*Math.PI*(d/waveLength))*amplitude*dampeningFactor;
		}
	}

	@Override
	public void setTime(double time) {
		radius = waveLength*(time/rotationTime);
	}
	
	public double getRotationTime() {
		return rotationTime;
	}

	public void setRotationTime(double rotationTime) {
		this.rotationTime = rotationTime;
	}

	public double getAmplitude() {
		return amplitude;
	}

	public void setAmplitude(double amplitude) {
		this.amplitude = amplitude;
	}

	public double getDampeningParameter() {
		return dampeningParameter;
	}
	
	public void setDampeningParameter(double dampeningParameter) {
		this.dampeningParameter = dampeningParameter;
	}

	public double getWaveLength() {
		return waveLength;
	}

	public void setWaveLength(double waveLength) {
		this.waveLength = waveLength;
	}

	public double getCenterX() {
		return centerX;
	}

	public double getCenterY() {
		return centerY;
	}
	
	public void setCenter(double x, double y)
	{
		centerX = x;
		centerY = y;
	}
	
	public CircleWave clone()
	{
		CircleWave result;
		try
		{
			result = (CircleWave)super.clone();
		}
		catch (CloneNotSupportedException e)
		{
			System.out.println(e.getMessage());
			return null;
		}
		
		result.centerX = centerX;
		result.centerY = centerY;
		result.waveLength = waveLength;
		result.amplitude = amplitude;
		result.rotationTime = rotationTime;
		result.dampeningParameter = dampeningParameter;
		
		return result;
	}
}
